package com.idealighter.game.mail.manager;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.core.constant.SysConfigId;
import com.idealighter.game.dictionary.dic.SysconfigDic;
import com.idealighter.game.dictionary.domain.SysconfigDomain;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.player.struct.Player;
import com.idealighter.game.server.db.datadb.dao.MailDao;
import com.idealighter.game.server.db.datadb.generate.domain.MailDomain;

import java.util.List;

@Singleton
public class MailMgr {
  private static final int MAIL_LIMIT = 20;

  @Inject
  private SysconfigDic sysconfigDic;
  @Inject
  private MailMsgMsg mailMsgMsg;
  private MailDao mailDao;

  @Inject
  public MailMgr(MailDao mailDao) {
    this.mailDao = mailDao;
  }

  /**
   * 获取邮件限制条数.
   * 
   * @return 条数.
   */
  private int getMailLimit() {
    SysconfigDomain cfgDom = sysconfigDic.get(SysConfigId.EMAIL_LIMIT);
    return cfgDom == null ? MAIL_LIMIT : Integer.parseInt(cfgDom.getVal());
  }


  /**
   * 邮件列表.
   * 
   * @param player 玩家.
   */
  public ResMessage mailList(Player player) {
    int mailLimit = getMailLimit();
    List<MailDomain> mailDomains = mailDao.selectByLimit(player.getId(), mailLimit);
    return mailMsgMsg.resMailList(mailDomains);


  }
}
